package portlet;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.jbo.ViewCriteria;
import oracle.jbo.ViewCriteriaRow;
import oracle.jbo.ViewObject;
import oracle.portlet.bridge.adf.application.ADFBridgePortlet;

public class chitietanpham extends ADFBridgePortlet {
    private Object baivietId;
    private Object tieude;
    private Object mota;
    private Object noidung;
    private Object chuyenmucid;
    private Object tenchuyenmuc;
    private Object soid;
    private Object sodientu;
    private Object sogiay;
    private Object ngayxuatban;
    private Object urlchitiet;
    private Object filedinhkem;
    private Object urldownload;
    private Object tacgia;
    private boolean hasFile = false;
    private boolean checkcount = false;
    private String viewRender;
    //Labels
    private String labelSoanpham;
    private String labelFiledinhkem;
    private String labelBaivietkhac;
    private String labelNgayxuatban;
    private String labelTacgia;
    
    public String getViewRender() {
        getBaivietId();
        getChitietBaiviet();
        getHtFileObject();
        getBaivietLienquan();
        return viewRender;
    }

    public void getChitietBaiviet() {
        DCIteratorBinding baivietIterator =
            Utils.getIteratorBinding("AptcBaivietView1Iterator");
        ViewObject vo = baivietIterator.getViewObject();
        ViewCriteria vc =
            vo.getViewCriteriaManager().getViewCriteria("AptcBaivietViewCriteria2");
        vo.ensureVariableManager().setVariableValue("varId", baivietId);
        vo.getViewCriteriaManager().removeApplyViewCriteriaName("AptcBaivietViewCriteria2");
        vo.getViewCriteriaManager().applyViewCriteria(vc);
        vo.setRangeSize(1);
        vo.executeQuery();
        if (vo.getAllRowsInRange().length > 0) {
            vo.setCurrentRowAtRangeIndex(0);            
            soid = vo.getCurrentRow().getAttribute("AptcSoId");
            filedinhkem = vo.getCurrentRow().getAttribute("FileId");
            tieude = vo.getCurrentRow().getAttribute("Tieude");
            mota = vo.getCurrentRow().getAttribute("Mota");
            noidung = vo.getCurrentRow().getAttribute("Noidung");
            tacgia = vo.getCurrentRow().getAttribute("TacGia");
            if (tacgia != null) {
                tacgia = getLabelTacgia() + ": " + tacgia;
            }
            chuyenmucid = vo.getCurrentRow().getAttribute("ChuyenmucId");

            DCIteratorBinding soIterator1 =
                Utils.getIteratorBinding("AptcSoView1Iterator");
            soIterator1.setCurrentRowWithKeyValue(soid.toString());
            sodientu = soIterator1.getCurrentRow().getAttribute("Sodientu");
            sogiay = soIterator1.getCurrentRow().getAttribute("Sogiay");

            ngayxuatban = soIterator1.getCurrentRow().getAttribute("Namxuatban");
            DCIteratorBinding chuyenmucIterator1 =
                Utils.getIteratorBinding("AptcChuyenmucView1Iterator");
            chuyenmucIterator1.setCurrentRowWithKeyValue(chuyenmucid.toString());
            tenchuyenmuc =
                    chuyenmucIterator1.getCurrentRow().getAttribute("Tieude");
        }
    }
    
    public void getHtFileObject() {
        DCIteratorBinding fileIterator =
            Utils.getIteratorBinding("HtFileView1Iterator");
        ViewObject vo = fileIterator.getViewObject();
        ViewCriteria vc = vo.createViewCriteria();
        ViewCriteriaRow cr = vc.createViewCriteriaRow();
        if (filedinhkem == null) {
            filedinhkem = 0;
        }
        String varStr = "IN (" + filedinhkem + ")";
        cr.setAttribute("Id", varStr);
        vc.addElement(cr);
        vo.getViewCriteriaManager().clearViewCriterias();
        vo.applyViewCriteria(vc);
        vo.executeQuery();
        if (vo.getAllRowsInRange().length > 0) {
            hasFile = true;
        }
    }

    public void getBaivietLienquan() {
        DCIteratorBinding soIterator =
            Utils.getIteratorBinding("AptcBaivietView1Iterator");
        ViewObject vo = soIterator.getViewObject();
        ViewCriteria vc =
            vo.getViewCriteriaManager().getViewCriteria("AptcBaivietViewCriteria1");
        vo.ensureVariableManager().setVariableValue("varSo", soid);
        vo.ensureVariableManager().setVariableValue("varChuyenmuc",
                                                    chuyenmucid);
        vo.ensureVariableManager().setVariableValue("varId", baivietId);
        vo.getViewCriteriaManager().removeApplyViewCriteriaName("AptcBaivietViewCriteria1");
        vo.getViewCriteriaManager().applyViewCriteria(vc);
        vo.setRangeSize(-1);
        vo.executeQuery();
        if (vo.getAllRowsInRange().length > 0) {
            checkcount = true;
        }
    }

    public Object getBaivietId() {
        try {
            baivietId = Utils.getPortletRequest().getParameter("id");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return baivietId;
    }

    public Object getTieude() {
        return tieude;
    }

    public Object getMota() {
        return mota;
    }

    public Object getNoidung() {
        return noidung;
    }

    public Object getChuyenmucid() {
        return chuyenmucid;
    }

    public Object getTenchuyenmuc() {
        return tenchuyenmuc;
    }

    public Object getSoid() {
        return soid;
    }

    public Object getSodientu() {
        return sodientu;
    }

    public Object getSogiay() {
        return sogiay;
    }

    public Object getNgayxuatban() {
        return ngayxuatban;
    }

    public Object getUrlchitiet() {
        try {
            urlchitiet = Utils.getPortletRequest().getParameter("urlchitiet");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return urlchitiet;
    }

    public Object getFiledinhkem() {
        return filedinhkem;
    }

    public Object getUrldownload() {
        try {
            urldownload = Utils.getPortletRequest().getParameter("urldownload");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return urldownload;
    }

    public Object getTacgia() {
        return tacgia;
    }

    public boolean isHasFile() {
        return hasFile;
    }

    public boolean isCheckcount() {
        return checkcount;
    }

    public String getLabelSoanpham() {
        labelSoanpham = Utils.getResource("AN_PHAM_SO", "lang3");
        return labelSoanpham;
    }

    public String getLabelFiledinhkem() {
        labelFiledinhkem = Utils.getResource("TAP_TIN_DINH_KEM", "lang3");
        return labelFiledinhkem;
    }

    public String getLabelBaivietkhac() {
        labelBaivietkhac = Utils.getResource("BAI_VIET_KHAC", "lang3");
        return labelBaivietkhac;
    }

    public String getLabelNgayxuatban() {
        labelNgayxuatban = Utils.getResource("NGAY_XUAT_BAN", "lang3");
        return labelNgayxuatban;
    }

    public String getLabelTacgia() {
        labelTacgia = Utils.getResource("TAC_GIA", "lang3");
        return labelTacgia;
    }
}
